#ifndef _KTV_APPLICATION_H_
#define _KTV_APPLICATION_H_

#include <SDL/SDL.h>
#include <list>
#include <string>
#include <map>
#include <memory>
#include "ui_window.h"
#include "ui_message_server.h"
#include "ui_message_client.h"
#include "ui_config_store.h"
#include "ui_log.h"
#include "ui_std_ex.h"


namespace
{
const int DEFAULT_BPP = 32;
const int DEFAULT_WIDTH = 600;
const int DEFAULT_HEIGHT = 480;
}


namespace UI
{

enum EAppLogSeverity
{
	APP_LOG_CRITICAL = 1,
	APP_LOG_ERROR = 3,
	APP_LOG_WARNING = 5,
	APP_LOG_INFO = 8
};


class UI_Application : public UI_MessageClient
{
protected:
	virtual void HandleSDLEvent(SDL_Event event);
	static UI_Application* m_pInstance;
	int m_iExitCode;
	bool m_bRunning;
	bool m_bInited;
	UI_Window* m_pKeyFocusWindow;
	UI_Window* m_pMouseFocusWindow;

	UI::UI_ConfigStore m_GlobalConfig;
	UI::UI_Log m_AppLog;
	int app_screen_width;
	int app_screen_height;
	int app_screen_bpp;
	SDL_Surface* m_pScreenSurface;
public:
	UI_Application();
	virtual ~UI_Application(void);
	static UI_Application* Instance(void) { return m_pInstance; }
	virtual int ExitCode(void) const { return m_iExitCode; }
	virtual bool IsRunning(void) const { return m_bRunning; }
	virtual bool IsInitialized(void) const { return m_bInited; }
	virtual void SetKeyFocus(UI_Window* pWindow);
	virtual UI_Window* GetKeyFocus(void) const { return m_pKeyFocusWindow; }
	virtual void SetMouseFocus(UI_Window* pWindow);
	virtual UI_Window* GetMouseFocus(void) const { return m_pMouseFocusWindow; }
	virtual void Init(void);
	virtual void Exec(void);
	virtual void ApplicationExit(int iExitCode = EXIT_SUCCESS);
	virtual int GetBitsPerPixel(void) const { return app_screen_bpp; }
	virtual int GetAppScreenWidth(void) const { return app_screen_width; }
	virtual int GetAppScreenHeight(void) const { return app_screen_height; }
	virtual SDL_Surface* GetAppScreen(void) { return m_pScreenSurface;}
	virtual void SetMousePosition( const UI_Point& Point ) { SDL_WarpMouse(stdex::safe_static_cast<Uint16>(Point.XPos()), stdex::safe_static_cast<Uint16>(Point.YPos())); }
	virtual void SetMouseVisibility( bool bVisible ) { SDL_ShowCursor(bVisible); }
	virtual const UI::UI_ConfigStore& GetGlobalConfig(void) { return m_GlobalConfig; }
	virtual UI::UI_Log& GetApplicationLog(void) { return m_AppLog; }
	virtual bool HandleMessage(UI_Message* pMessage);
	virtual bool IfReceiveEvent(void) const { return true; }
};


}


#endif // _KTV_APPLICATION_H_
